package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.NewsDaoImpl;
import com.ysd.dao.impl.NewsDetailsDaoImpl;
import com.ysd.entity.NewsClassify;
import com.ysd.entity.NewsDetails;


public class NewsDetallServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//咨询的分类
		NewsDaoImpl news = new NewsDaoImpl();
		List<NewsClassify> newsList = news.getNews();
		request.setAttribute("newsList", newsList);
		
		//接收前台传来的cId,并转为int类型
		int nId = Integer.parseInt(request.getParameter("newsDetailsId"));
		NewsDetailsDaoImpl nDetails = new NewsDetailsDaoImpl();
		List<NewsDetails> neList = nDetails.getNewDetails(nId);
		request.setAttribute("neList", neList);
		
		//上一条
		int aId = Integer.parseInt(request.getParameter("newsDetailsId"));
		NewsDetailsDaoImpl Details = new NewsDetailsDaoImpl();
		List<NewsDetails> seList = Details.skipNewDetails(aId);
		request.setAttribute("seList", seList);
				
		//下一条
		int bId = Integer.parseInt(request.getParameter("newsDetailsId"));
		NewsDetailsDaoImpl skipDetails = new NewsDetailsDaoImpl();
		List<NewsDetails> skipList = skipDetails.skipNewsDetails(bId);
		request.setAttribute("skipList", skipList);
		
		request.getRequestDispatcher("article_list_content.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
